//
//  NSAttributedString+YTAdd.m
//  tesDemo02
//
//  Created by 拓客营 on 2022/3/21.
//

#import "NSAttributedString+YTAdd.h"

@implementation NSAttributedString (YTAdd)

- (CGSize)sizeForWidth:(CGFloat)width {
    CGSize size = CGSizeMake(width, CGFLOAT_MAX);
    
    return [self boundingRectWithSize:size options:NSStringDrawingUsesLineFragmentOrigin context:nil].size;
}

+ (NSAttributedString *)attributedString:(NSString *)string attributes:(NSDictionary *)attributes {
    return [[NSAttributedString alloc] initWithString:string attributes:attributes];
}

+ (NSAttributedString *)toAttributedWithHtmlStr:(NSString *)htmlStr {
    return [[NSAttributedString alloc] initWithData:[htmlStr dataUsingEncoding:NSUnicodeStringEncoding] options:@{NSDocumentTypeDocumentAttribute: NSHTMLTextDocumentType} documentAttributes:nil error:nil];
}

@end
